package src.edu.wayne.cs.csc4110.hw6.tests;

import static org.junit.Assert.*;

import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import src.edu.wayne.cs.csc4110.hw6.implementations.dbase.FacelookDatabaseImpl;
import src.edu.wayne.cs.csc4110.hw6.implementations.dbase.StatusImpl;
import src.edu.wayne.cs.csc4110.hw6.implementations.dbase.UserImpl;
import src.edu.wayne.cs.csc4110.hw6.interfaces.FacelookDatabase;
import src.edu.wayne.cs.csc4110.hw6.interfaces.Status;
import src.edu.wayne.cs.csc4110.hw6.interfaces.User;

public class DatabaseTests {
	
	User testUser;
	FacelookDatabase database = new FacelookDatabaseImpl();

	public FacelookDatabase getDataBase()
	{
		return this.database;
	}
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	public void loadUsersAndStatuses(boolean loadStatus, boolean loadFriends) 
	{
		String email, userName, password, message;
		User tempUser;
		
		testUser = new UserImpl("cr3550@wayne.edu", "kd8amo", "password");
		database.register(testUser);

		for (int i=1;i < 20;i++)
		{
			password = new String("password");
			email = new String("user");
			userName = new String("User ");
			userName = userName.concat(Integer.toString(i));
			email = email.concat(Integer.toString(i));
			password = password.concat(Integer.toString(i));
			email = email.concat("@wayne.edu");
			tempUser = new UserImpl(email, userName, password);
			database.register(tempUser);
			
			if (loadFriends)
				database.storeFriend(testUser, tempUser);
			
			if (loadStatus)
			{
				for (int j=0;j < 10;j++)
				{
					message = new String(userName).concat(Integer.toString(j));
					Status tempStatus = new StatusImpl(message, tempUser, new Date());
					database.storeStatus(tempStatus);				
				}
			}
			
		}
	}
	
	
	@Before
	public void setUp() throws Exception {
		
		loadUsersAndStatuses(true, true);

	}

	@After
	public void tearDown() throws Exception {
	}


	@Test
	/**
	 * Checks for various friendship problems.
	 */
	public void checkForFriends()
	{
		User userNotInDbase = new UserImpl("notAUser@wayne.edu", "No Body", "badPassword");
		assertEquals(database.areFriends(testUser, userNotInDbase), false);
		assertEquals(database.areFriends(testUser, database.getUser("user1@wayne.edu")), true);
	}

}
